/*
 * TreeDelegate.h  0.4.0 / Nov 30, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
#ifndef TREEDELEGATE_H
#define TREEDELEGATE_H

#include "Cute4jSwing.h"

#include "ComponentDelegate.h"
#include "QIconAdapter.h"
#include "QTreeViewAdapter.h"
#include "TreeModel.h"

// TreeDelegate Class. ---------------------------------------------------------

/*!
 * \brief Tree Delegate.
 *
 * \author Slobodan Vrkacevic
 * \version 0.4.0
 */
class CUTE4J_EXPORT TreeDelegate : public ComponentDelegate
{
  Q_OBJECT
protected:
  TreeDelegate(JNIEnv *env, jobject obj);
  virtual ~TreeDelegate();
public: // native calls
  void createIcon(JNIEnv *env, jobject iconSet);
  void setUseModel(JNIEnv *env, jboolean useModel);
public: // native calls
  static void initialize(JNIEnv *env, jclass cls, jclass treeNodeClass);
  static jlong newInstance(JNIEnv *env, jobject obj);
public: // native callbacks
  jobject getRootNode();
  void nodeSelected(jobject node);
  jboolean setNodeIcon(jobject node);
public:
  QIcon *getNodeIcon(jobject node);
public:
  inline QTreeViewAdapter *qTreeView() const;
public:
  virtual jobject getBackground(JNIEnv *env, jclass colorClass);
  virtual void setBackground(JNIEnv *env, jint argb);
  virtual void setNullBackground(JNIEnv *env);
  virtual jint getCursor(JNIEnv *env);
  virtual void setCursor(JNIEnv *env, jint type);
protected slots:
  void selectionChangedSlot(const QItemSelection &selected,
                            const QItemSelection &deselected);
private:
  QIconAdapter *m_nodeIcon;
  TreeModel *m_treeModel;
  QItemSelectionModel *m_treeSelectionModel;
private:
  static jmethodID sm_getRootNodeMID;
  static jmethodID sm_setNodeIconMID;
  static jmethodID sm_nodeSelectedMID;
};

// TreeDelegate :: Public Inline Member Function. ------------------------------

/*!
 * \brief Returns QTreeViewAdapter adaptee.
 *
 * \return QTreeViewAdapter adaptee
 */
inline QTreeViewAdapter *TreeDelegate::qTreeView() const
{
  return static_cast<QTreeViewAdapter *>(qObject());
}

// Macro Definitions. ----------------------------------------------------------

#define TREE_DELEGATE (reinterpret_cast<TreeDelegate *>(delegate))

#endif // TREEDELEGATE_H
